<template>
    <!-- 治疗开单 -->
    <div class="app-container">
        <div class="head-container">
            <div class="head-info">
                <div class="name">
                    <strong>{{ content.patientInfo.patientName }}</strong>
                </div>

                <div class="info">
                    <div>
                        {{ getGenderText(content.patientInfo.gender) }}
                    </div>
                    <div>{{ content.patientInfo.age }} 岁</div>
                    <div>{{ content.patientInfo.outpatientNum }}</div>
                </div>
            </div>

            <div class="head-btn">
                <el-button type="primary" :disabled="!content.treatmentInformedInfo" size="mini"
                    @click="dialogVisible = true">知情同意书</el-button>
                <el-button type="primary" :disabled="!content.adviceHyperbaricOxygen" size="mini"
                    @click="dialogFormVisible = true">操舱医嘱</el-button>
                <el-button type="primary" size="mini" @click="goBack()">返回</el-button>
            </div>
        </div>

        <div class="body">
            <div id="right">
                <div id="right-top">
                    <div id="right-top-info">
                        <div><strong>治疗项目明细</strong></div>
                        <div>
                            每次固定治疗时间: &nbsp;
                            <el-input v-model="content.adviceTime" prefix-icon="el-icon-timer" disabled
                                class="width-120" />
                            &nbsp;
                            <strong>总金额: &nbsp;&nbsp;<i>{{ content.totalAmount }}</i>元</strong>
                        </div>
                    </div>

                    <el-table :data="content.adviceList" style="width: 100%" height="330" highlight-current-row
                        :header-cell-style="{ background: '#eef1f6', color: '#606266' }"
                        @selection-change="handleSelectionChange">
                        <el-table-column label="自费" align="center">
                            <template #default="{ row }">
                                <el-checkbox :value="row.insuranceType == 0"
                                    @input="updateInsuranceType(row)"></el-checkbox>
                            </template>
                        </el-table-column>
                        <el-table-column type="index" label="序号" align="center" fixed />
                        <el-table-column prop="treatmentName" label="项目名称" align="center" />
                        <el-table-column prop="exePeriod" label="疗程" align="center" />
                        <el-table-column prop="periodNum" label="疗程次数" align="center" />
                        <el-table-column prop="exeInterval" label="执行间隔" align="center" />
                        <el-table-column prop="singleNum" label="单次数量" align="center" />
                        <el-table-column prop="dicItemUnitName" label="单位" align="center" />
                        <el-table-column prop="exeDepartmentName" label="执行科室" align="center" />
                        <el-table-column prop="unitPrice" label="单价" align="center" />
                        <el-table-column prop="adviceStates" label="状态" align="center">
                            <template #default="{ row }">
                                <el-tag :type="getStatusText(row.adviceStates)[1]" effect="plain">
                                    {{ getStatusText(row.adviceStates)[0] }}
                                </el-tag>
                            </template>
                        </el-table-column>
                    </el-table>
                </div>

                <div id="right-down">
                    <div id="right-down-info">
                        <div><strong>治疗评估</strong></div>
                    </div>

                    <el-table :data="content.estimateList" height="330"
                        :header-cell-style="{ background: '#eef1f6', color: '#606266' }">
                        <el-table-column type="index" label="序号" align="center" fixed />

                        <el-table-column prop="estimateName" label="治疗评估表" align="center" />

                        <el-table-column prop="estimateStates" label="状态" align="center">
                            <template #default="{ row }">
                                <el-tag :type="row.estimateStates ? 'success' : 'warning'" effect="plain">
                                    {{ row.estimateStates ? "已评估" : "未评估" }}
                                </el-tag>
                            </template>
                        </el-table-column>

                        <el-table-column label="操作" align="center"
                            :header-cell-style="{ background: '#eef1f6', color: '#606266' }">
                            <template #default="{ row }">
                                <el-link type="primary" v-show="!row.estimateStates" :disabled="allAdviceStatesAre5"
                                    @click="clickAssess(row)">评估</el-link>
                                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                <el-link type="success" v-show="row.estimateStates ||
                                    row.estimateId == 3 ||
                                    row.estimateId == 8 ||
                                    row.estimateId == 9" @click="clickDetail(row)">详情</el-link>
                            </template>
                        </el-table-column>
                    </el-table>
                </div>
            </div>
        </div>

        <el-dialog title="知情同意书" :visible.sync="dialogVisible">
            <informedConsent :patientInfo="content.patientInfo" :treatmentInformedInfo="content.treatmentInformedInfo"
                :isSign="isSign" />
            <div slot="footer" class="dialog-footer">
                <el-button type="primary" @click="dialogFormVisible = false">退 出</el-button>
            </div>
        </el-dialog>

        <el-dialog title="操舱医嘱" :visible.sync="dialogFormVisible">
            <medicalAdvice :propData="content" :isDisabled="isDisabled" />
            <div slot="footer" class="dialog-footer">
                <el-button type="primary" @click="dialogFormVisible = false">退 出</el-button>
            </div>
        </el-dialog>
    </div>
</template>

<script>
import { sendAdviceQuery, sendInfoQuery } from "@/api/outpatient/medicalAdvice";
import MedicalAdvice from "@/views/outpatient/treatmentBilling/MedicalAdvice";
import InformedConsent from "@/views/outpatient/treatmentBilling/InformedConsent";

//评定表path
const assessList = [
    {
        name: "针灸医疗记录单",
        editRoute: "acupunctureTemplate",
        detailRoute: "acupunctureTemplate",
        type: 13
    },
    {
        name: "康复治疗记录单",
        editRoute: "rehabRecordTemplate",
        detailRoute: "rehabRecordTemplate",
        type: 14
    },
    {
        name: "临床康复介入医疗记录单",
        editRoute: "clinicalRecordTemplate",
        detailRoute: "clinicalRecordTemplate",
        type: 15
    },
    {
        name: "滨江高压氧治疗的心理护理及安全告知书",
        editRoute: "hyperbaricNoticeBJTemplate",
        detailRoute: "hyperbaricNoticeBJTemplate",
        type: 16
    },
    {
        name: "高压氧治疗的心理护理及安全告知书",
        editRoute: "hyperbaricNoticeTemplate",
        detailRoute: "hyperbaricNoticeTemplate",
        type: 17
    },
    {
        name: "舱内治疗评估",
        editRoute: "chamberEvalTemplate",
        detailRoute: "chamberEvalTemplate",
        type: 18
    },
    // {
    //     type: 1,
    //     name: "吞咽功能障碍评定",
    //     editRoute: "SwallowEdit",
    //     detailRoute: "SwallowView",
    // },
    // {
    //     type: 2,
    //     name: "肺功能和日常生活评定表",
    //     editRoute: "PulmonaryEdit",
    //     detailRoute: "PulmonaryView",
    // },
    // {
    //     type: 3,
    //     name: "周围性面神经炎治疗成绩评分表",
    //     editRoute: "FacialNerveEdit",
    //     detailRoute: "FacialNerveView",
    // },
    // {
    //     type: 4,
    //     name: "初期康复评定记录表",
    //     editRoute: "EarlyEdit",
    //     detailRoute: "EarlyView",
    // },
    // {
    //     type: 5,
    //     name: "中期康复评定记录表",
    //     editRoute: "MidTermEdit",
    //     detailRoute: "MidTermView",
    // },
    // {
    //     type: 6,
    //     name: "出院前康复评定记录表",
    //     editRoute: "DischargeEdit",
    //     detailRoute: "DischargeView",
    // },
    // {
    //     type: 7,
    //     name: "偏瘫运动功能评定表",
    //     editRoute: "HemiplegiaEdit",
    //     detailRoute: "HemiplegiaView",
    // },
    // {
    //     type: 8,
    //     name: "神经损伤功能评定表",
    //     editRoute: "NerveInjuryEdit",
    //     detailRoute: "NerveInjuryView",
    // },
    // {
    //     type: 9,
    //     name: "神经康复综合评定表",
    //     editRoute: "NeurorehabilitationEdit",
    //     detailRoute: "NeurorehabilitationView",
    // },
    // {
    //     type: 10,
    //     name: '感知能力-耳聋分级',
    //     editRoute: 'DeafGradeEdit',
    //     detailRoute: 'DeafGradeView'
    // },
    // {
    //     type: 11,
    //     name: '感知能力-程度评估',
    //     editRoute: 'DegreeEdit',
    //     detailRoute: 'DegreeView'
    // },
    // {
    //     type: 12,
    //     name: '运动能力',
    //     editRoute: 'MotionEdit',
    //     detailRoute: 'MotionView'
    // }
];

export default {
    data() {
        return {
            dialogFormVisible: false,
            dialogVisible: false,
            list: [],
            isDisabled: true,
            isSign: false,
            batchId: null,  //批号
            allAdviceStatesAre5: false,
            content: {
                // patientInfo: {
                //     patientId: "患者ID",
                //     patientName: "患者姓名",
                //     age: "年龄",
                //     patientType: "患者类别 1=门诊 2=住院 3=其他",
                //     gender: "性别 0=女 1=男",
                //     bedNum: "床号",
                //     admissionNum: "住院号",
                //     outpatientNum: "门诊号",
                // },
                // adviceList: [
                //     // {
                //     //     adviceStates:
                //     //         "医嘱状态： 0=未提交 1=已提交 2=已签署 3=执行中 4=已完成 5=已作废",
                //     //     treatmentName: "治疗项目名称",
                //     //     index: "序号",
                //     //     adviceId: "医嘱ID",
                //     //     treatmentId: "治疗项目ID",
                //     //     insuranceType: "保险类型 0=自费 1=医保",
                //     //     exePeriod: "执行疗程",
                //     //     periodNum: "疗程次数",
                //     //     exeInterval: "执行间隔",
                //     //     dicExeInterval: "执行间隔单位",
                //     //     singleNum: "单次数量",
                //     //     dicItemUnit: "单位",
                //     //     dicItemUnitName: "项目单位名称",
                //     //     exeDepartmentCode: "执行科室编码",
                //     //     exeDepartmentName: "执行科室名称",
                //     //     unitPrice: "单价",
                //     // },
                // ],
                // adviceTime: "治疗时间 格式 HH:mm",
                // totalAmount: "总金额",
                // estimateList: [
                //     // {
                //     //     index: "序号",
                //     //     estimateId: "评估表ID",
                //     //     estimateName: "评估表名称",
                //     //     estimateStates: "状态：0=未评估 1=已评估",
                //     // },
                // ],
                // treatmentInformedInfo: {
                //     informedInfoId: "治疗知情同意书ID",
                //     signName: "患方签名",
                //     treatmentTarget:
                //         "检查目的 1=明确病因,完善诊断 2=确定治疗方案，判断预后 3=对症治疗，缓解病情 4=其他  多个逗号隔开",
                //     dicPatientRelation: "与患者关系 字典ID",
                //     coreRisk: "主要风险 1-13代表不同风险  多个逗号隔开",
                //     fingerprint: "患方指纹",
                // },
                // adviceHyperbaricOxygen: {
                //     hyperbaricOxygenId: "高压氧操仓医嘱ID",
                //     adviceNote: "注意事项",
                //     gaugePressure: "表压",
                //     singleOxygenMinute: "单次吸氧分钟数",
                //     singleOxygenNum: "单次吸氧次数",
                //     intervalOxygenMinute: "间隔吸氧分钟数",
                //     intervalOxygenNum: "间隔吸氧次数",
                //     exePeriod: "疗程次/日",
                //     periodNum: "疗程天数",
                //     doctorSign: "医生签名",
                //     curativeEffect: "疗效  1=治愈、2=显著、3=有效、4=无效",
                //     treatmentInterruptionReason:
                //         "中断治疗原因  1=治愈、2=无效  3=出院 4=不适应 5=其他",
                //     briefCondition: "病情简要",
                // },
            },
        };
    },
    components: {
        medicalAdvice: MedicalAdvice,
        informedConsent: InformedConsent,
    },
    computed: {
        batchId() {
            return this.$store.state.common.batchId;
        },
        isInsuranceSelected() {
            return {
                get() {
                    return this.row.insuranceType === 1;
                },
                set(value) {
                    this.row.insuranceType = value ? 1 : 0;
                },
            };
        },
    },

    mounted() {
        this.batchId = this.$route.params.batchId;
        this.getMedicalAdvice();
        sendInfoQuery().then((res) => {
            console.log(res);
        });
    },

    methods: {
        // 医嘱详情请求
        getMedicalAdvice() {
            sendAdviceQuery(this.batchId).then((res) => {
                console.log(res, "resresres");

                if (res.code == 0) {
                    this.content = res.content;
                    this.allAdviceStatesAre5 = this.content.adviceList.every(item => item.adviceStates == 5);
                } else {
                    this.$notify({
                        title: "警告",
                        message: res.msg,
                        type: "danger",
                    });
                }
            });
        },

        updateInsuranceType(row) {
            row.insuranceType = row.insuranceType === 1 ? 0 : 1;
        },

        //点击评估
        clickAssess(row) {
            if (!this.batchId) {
                this.$notify({
                    title: "提示",
                    message: "请先保存后再进行评估",
                    type: "warning",
                });
                return;
            }
            let target = assessList.find((item) => item.type == row.estimateId);
            this.$router.push({
                name: target.editRoute,
                query: { type: 0, source: 2, id: this.batchId },
            });
        },

        //点击详情
        clickDetail(row) {
            let target = assessList.find((item) => item.type == row.estimateId);
            this.$router.push({
                name: target.detailRoute,
                query: { type: 1, source: 2, id: this.batchId },
            });
        },

        goBack() {
            this.$router.push("/outpatient/historyApply");
        },

        getGenderText(Gender) {
            switch (Gender) {
                case 0:
                    return "女";
                case 1:
                    return "男";
                default:
                    return "";
            }
        },

        getStateText(State) {
            switch (State) {
                case 0:
                    return ["未评估", "info"];
                case 1:
                    return ["已评估", "parmary"];
                default:
                    return "";
            }
        },
        getStatusText(status) {
            switch (status) {
                case 0:
                    return ["未提交", "info"];
                case 1:
                    return ["已提交", ""];
                case 2:
                    return ["已签署", "success"];
                case 3:
                    return ["执行中", "warning"];
                case 4:
                    return ["已完成", "success"];
                case 5:
                    return ["已作废", "danger"];
                default:
                    return ["未知状态", "info"];
            }
        }
    },
};
</script>

<style lang='scss' scoped>
/deep/ .el-dialog__body {
    padding: 0px;
}

.app-container {
    background-color: #fff;
    padding-bottom: 0;

    .width-80 {
        width: 80px;
    }

    .width-120 {
        width: 120px;
    }

    .width-150 {
        width: 150px;
    }

    .width-180 {
        width: 180px;
    }

    .head-container {
        display: flex;
        align-items: center;
        justify-content: space-between;

        .head-info {
            display: flex;
            justify-content: start;
            align-items: center;

            .name {
                font-weight: 900;
            }

            .info {
                font-weight: 300;
                display: flex;
                justify-content: start;
                align-items: center;

                div {
                    margin-right: 12px;
                }
            }
        }

        .head-info>div {
            margin: 0 15px;
        }

        .head-btn {
            .el-button {
                margin: 0 10px;
            }
        }
    }

    .body {
        width: 100%;
        height: 800px;
        max-height: 800px;
        box-sizing: border-box;
        padding-bottom: 10px;
        border: 1px solid #ccc;
        display: flex;

        #right {
            width: 100%;
            // flex: 1;
            padding: 5px 10px;
            border-left: 1px solid #ccc;

            #right-top {
                width: 100%;
                border-bottom: 1px solid #ccc;
                margin-bottom: 20px;

                #right-top-info {
                    height: 38px;
                    padding: 0 0 10px;
                    display: flex;
                    justify-content: space-between;
                    align-items: center;

                    i {
                        font-style: normal;
                        color: red;
                    }
                }
            }

            #right-down {
                width: 100%;

                #right-down-info {
                    height: 38px;
                    padding: 0 0 10px;
                    display: flex;
                    justify-content: space-between;
                    align-items: center;
                }
            }
        }
    }
}
</style>
